package com.cpe.transfer.classproject;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import com.cpe.data.domain.classsproject.ClassProject;
import com.cpe.data.domain.classsproject.ClassProjectInfo;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;

@Component
public class ClassProjectTransfer {
	/**
	 * 实体-->响应
	 */
	public ClassProjectInfo toInfo(ClassProject classProject) {
		Assert.notNull(classProject);
		ClassProjectInfo info = new ClassProjectInfo();
		BeanUtils.copyProperties(classProject, info);
		return info;
	}

	/**
	 * 实体分页-->响应分页
	 */
	public PageInfo<ClassProjectInfo> toPageInfo(List<ClassProject> classProjects) {
		Assert.notNull(classProjects);
		PageInfo<ClassProject> pageInfo = new PageInfo<>(classProjects);
		PageInfo<ClassProjectInfo> pageResp = new PageInfo<>();
		BeanUtils.copyProperties(pageInfo, pageResp);
		List<ClassProjectInfo> infoList = Lists.newArrayList();
		for (ClassProject classProject : classProjects) {
			infoList.add(toInfo(classProject));
		}
		pageResp.setList(infoList);
		return pageResp;
	}
}
